package com.healthcare.client.controller;


import com.healthcare.client.pojo.User;
import com.healthcare.client.service.UserService;
import com.healthcare.client.utils.Cookietwo;
import com.healthcare.client.utils.SessionUtils;
import com.healthcare.client.vo.LoginForm;
import com.healthcare.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 新华医院转诊联盟
 * @since 2020-04-13
 */
@Api(tags = "前台用户管理")
@CrossOrigin
@RestController
@RequestMapping("/client/user")
public class UserController {

    @Autowired
    private UserService userService;

   /* @ApiOperation("前台登录方法")
    @GetMapping("login/{mobile}/{password}")
    private Result Login(
            @ApiParam(name = "mobile",value = "手机号",required = true)
            @PathVariable String mobile,
            @ApiParam(name = "password",value = "密码",required = true)
            @PathVariable String password){
        User user =  userService.Login(mobile,password);

        return Result.ok().data("user",user);
    }*/

    @ApiOperation("前台登录方法")
    @PostMapping("login")
    private Result Login(
              @ApiParam(name = "loginForm",value = "登录对象",required = true)
              @RequestBody  LoginForm loginForm
            ){
        User user =  userService.Login(loginForm.getMobile(),loginForm.getPassword());
        return Result.ok().data("user",user);
    }

    @ApiOperation("查询今天是否有会诊和转诊记录")
    @GetMapping("getclinicalstage/{identity}")
    public Result getClinicalStageMesage(
            @ApiParam(name = "identity",value = "辨识身份值 0-1 ",required = true)
            @PathVariable Integer identity){
        Map<String,Object> map =  userService.getClinicalStageMesage(identity);
        return Result.ok().data("datas",map);
    }

    @ApiOperation("获取登录医生")
    @GetMapping("getDoctor")
    public Result getDoctorSession(){
        User user = (User)SessionUtils.getSessionAttr("doctor");
        return Result.ok().data("user",user);
    }

    @ApiOperation("获取登录小助手")
    @GetMapping("getAdmin")
    public Result getAdminSession(){
        User user = (User)SessionUtils.getSessionAttr("admin");
        return Result.ok().data("admin",user);
    }


    @ApiOperation("查询通讯录列表")
    @GetMapping("getUserList")
    public Result getUserList(){
        Map<String,Object> map = userService.userList();
        return Result.ok().data("item",map);
    }

    @ApiOperation("通过医生姓名查询通讯录列表")
    @GetMapping("getUserListName/{userName}")
    public Result getUserListName(
            @ApiParam(name = "userName",value = "医生姓名",required = false)
            @PathVariable String userName){
        List<User> list = userService.userListName(userName);
        return Result.ok().data("list",list);
    }

    @ApiOperation("获取小助手和医生个人信息")
    @GetMapping("getProfile/{type}")
    public Result getProfile(@PathVariable  Integer type){
        User user  =userService.getProfile(type);
        return Result.ok().data("datas",user);
    }
}

